package repository

import (
	"recruit_student_backend/internal/model"
)

// CreateStudent 创建新学生记录
func CreateStudent(student *model.Student) error {
	return DB.Create(student).Error
}

// GetStudentByID 根据ID获取学生信息
func GetStudentByID(id uint) (*model.Student, error) {
	var student model.Student
	err := DB.First(&student, id).Error
	if err != nil {
		return nil, err
	}
	return &student, nil
}

// GetAllStudents 获取所有学生列表
func GetAllStudents() ([]model.Student, error) {
	var students []model.Student
	err := DB.Find(&students).Error
	if err != nil {
		return nil, err
	}
	return students, nil
}

// GetStudentsByPage 获取分页的学生列表
func GetStudentsByPage(page, pageSize int) ([]model.Student, error) {
	var students []model.Student
	offset := (page - 1) * pageSize
	err := DB.Offset(offset).Limit(pageSize).Find(&students).Error
	if err!= nil {
		return nil, err
	}
	return students, nil
}

// UpdateStudent 更新学生信息
func UpdateStudent(student *model.Student) error {
	return DB.Save(student).Error
}

// DeleteStudent 删除学生记录
func DeleteStudent(id uint) error {
	return DB.Delete(&model.Student{}, id).Error
}
